#include <gtest/gtest.h>
#include "al_design/trichotomy.hpp"
#include "al_design/big_num.h"

using namespace std;

int main(int argc, char *argv[]) {
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

TEST(AL_DESIGN, trichotomy) {
    int a[] = {1, 2, 3, 2, 1};
    ASSERT_EQ(trichotomy_max(a, 5), 2);

    int b[] = {3, 2, 1, 2, 3};
    ASSERT_EQ(trichotomy_min(b, 5), 2);

    int c[] = {3, 2, 1, 2, 3};
    int key = 2;
    int i = trichotomy_min_search(c, 5, key);
    ASSERT_EQ(b[i], key); // 是否搜索到了
    key = 3;
    i = trichotomy_min_search(c, 5, key);
    ASSERT_EQ(b[i], key);
    key = 1;
    i = trichotomy_min_search(c, 5, key);
    ASSERT_EQ(b[i], key);
}

TEST(AL_DESIGN, BIG_NUM) {
    ASSERT_EQ(big_mul("99", "99"), "9801");
    ASSERT_EQ(big_mul("2", "2"), "4");
    ASSERT_EQ(big_mul("7", "9"), "63");
    ASSERT_EQ(big_mul("8239443", "0"), "0");
    ASSERT_EQ(big_mul("87", "25"), "2175");
    ASSERT_EQ(big_mul("812", "38"), "30856");
    ASSERT_EQ(big_mul("1287821", "1232"), "1586595472");
    ASSERT_EQ(big_mul("2348723847384823487126348162376238746236876128342934", "27349823847192873456235423492384938247128374987239847328479"), "64237183491676040480281566712093436780675279396077614712553375205234489633040231064446535637689359453056617386");
}
